package org.example.network.demo1;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.StandardCharsets;

/**
 * @author Gong.Yang
 */
public class ByteBufferAPIDemo {

    public static void main(String[] args) {

    }

    /**
     * ByteBuffer to String
     */
    public String decode(ByteBuffer buf) {
        CharBuffer charBuffer = StandardCharsets.UTF_8.decode(buf);
        return charBuffer.toString();
    }

    /**
     * String to ByteBuffer
     */
    public ByteBuffer encoder(String content) {
        return StandardCharsets.UTF_8.encode(content);
    }
}
